import axios from "axios";
import {BackendPageModel} from "@/models/BackendPageModel";
import TemplateModel from "@/models/TemplateModel";

export function getTemplate(nameLike = '', pageNum = 1, pageSize = 10,): Promise<BackendPageModel<TemplateModel>> {
    return new Promise((resolve, reject) => {
        axios({
            method: 'get',
            url: '/api/customer/page',
            params: {pageNumber: pageNum - 1, pageSize: pageSize, name: nameLike}
        }).then(value => {
            resolve(value.data);
        }).catch(reason => {
            console.log(reason);
            reject();
        })
    })
}

export function getTemplateById(id: string): Promise<TemplateModel> {
    return new Promise((resolve, reject) => {
        axios({method: 'get', url: `/api/customer/${id}`}).then(value => {
            resolve(value.data);
        }).catch(reason => {
            reject();
        });
    });
}

export function insertTemplate(customer: TemplateModel | null): Promise<TemplateModel> {
    return new Promise((resolve, reject) => {
        axios({method: 'post', url: '/api/customer', data: customer}).then(value => {
            resolve(value.data);
        }).catch(reason => {
            console.log(reason);
            reject();
        })
    })
}